Fix search order in premake.findProjectScript#2678
Open
mercury233 wants to merge 1 commit intopremake:masterfrom
Open
Fix search order in premake.findProjectScript#2678mercury233 wants to merge 1 commit intopremake:masterfrom
premake.findProjectScript#2678mercury233 wants to merge 1 commit intopremake:masterfrom
Conversation
Jarod42
approved these changes
Apr 30, 2026
nickclark2016
approved these changes
May 1, 2026
Member
nickclark2016
left a comment
There was a problem hiding this comment.
Looks good at first glance, but I want to let this get more eyes on it and let it stew in my mind for a bit before merging. Thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
fix #1783
Current problem:
When
include("abc")is called, Premake looks for those files under each directory inpremake.path:abcabc.luaabcsubdirectorypremake.pathincludes the directory of the currently executing script, paths specified via command-line arguments or environment variables,~/.premake,/usr/local/share/premake, the directory containing the Premake executable, etc.The concrete search order is: for each candidate filename, search through all these path entries in order, stopping when a match is found.
This creates a problem: entries toward the end of
premake.pathare supposed to serve as fallback locations, yet the first candidate filename may match against them. For example,include("bitmap")intends to load./bitmap/premake5.lua, but if the Premake executable lives in/usr/binand that directory happens to contain a file namedbitmap, that file is returned, even though it is a binary executable.Fix:
Perform a local file-system pass over all candidate filenames first, before delegating to
os.locatefor path-based search.Update the documentation to describe the search order and the automatic
.luaextension behavior.How does this PR change Premake's behavior?
Before this change, a file in an external search path whose name matches the first candidate for
include("bitmap")would be loaded in preference to a local./bitmap/premake5.lua. After this change,./bitmap/premake5.luais loaded first.This is unlikely to break existing users: anyone loading a shared lua script from an external path would not normally also have a same-named lua script in the working directory, and would not normally omit the
.luaextension.Anything else we should know?
This fix mitigates the most common manifestation of the problem. The underlying ordering issue remains.
os.isfileis affected bydo_chdirinlua_auxlib.c, so it also operates relative to the directory of the currently executing script.The current implementation intermingles the code paths for searching embedded scripts and file-system scripts, making it harder to maintain and potentially introducing subtle bugs. Further refactoring may be warranted.
Did you check all the boxes?
closes #XXXXin comment to auto-close issue when PR is merged)You can now support Premake on our OpenCollective. Your contributions help us spend more time responding to requests like these!